package com.emex.app.stuff.utils;

import com.emex.app.shared.data.wrapper.OrderStatusWrapper;
import java.awt.Color;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author Sergey Karavaev
 */
public class OrderStatusTableCellRenderer  extends JLabel
        implements TableCellRenderer {

    public OrderStatusTableCellRenderer() {
        setOpaque(true); //MUST do this for background to show up.
    }

    @Override
    public Component getTableCellRendererComponent(
            JTable table, Object value,
            boolean isSelected, boolean hasFocus,
            int row, int column) {
        setText(" " + value);

        if (isSelected) {
            setForeground(Color.WHITE);
            setBackground(Color.BLUE);
        } else {
            setForeground(Color.BLACK);
            setBackground(Color.WHITE);
        }

        if (value != null && (value instanceof OrderStatusWrapper)) {
            setForeground(Color.BLACK);
            OrderStatusWrapper os = (OrderStatusWrapper) value;
            setText(os.toString());
            if (os.isOk()) {
                setBackground(Color.GREEN);
            } else {
                setBackground(Color.RED);
            }
        }

        return this;
    }
}